package _04_栈与队列;

import _02_动态数组.ArrayList;
import _01_第一季._00_公共接口.Stack;

/*
    底层由动态数组实现的顺序栈
 */
public class ArrayStack<E> implements Stack<E> {
    private ArrayList<E> list = new ArrayList<>();

    @Override
    public int size() {
        return list.size();
    }

    @Override
    public boolean isEmpty() {
        return list.isEmpty();
    }

    //将动态数组尾部当成栈顶
    @Override
    public void push(E  element) {
        list.add(element);
    }

    @Override
    public E pop() {
        return list.remove(list.size()-1);
    }

    @Override
    public E top() {
        return list.get(list.size()-1);
    }

    @Override
    public void clear() {
        list.clear();
    }
}
